#pragma once

#include"RBTree.h"

namespace lh
{
	template<class K>
	class set
	{
		struct Set_Of_Type
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename RBTree<K, K, Set_Of_Type>::Iterator iterator;
		typedef typename RBTree<K, K, Set_Of_Type>::ConstIterator const_iterator;

		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}

		const_iterator begin() const
		{
			return _t.Begin();
		}

		const_iterator end() const
		{
			return _t.End();
		}

		pair<iterator,bool> insert(const K& key)
		{
			return _t.Insert(key);
		}

		iterator find(const K& key)
		{
			return _t.Find(key);
		}

	private:
		RBTree<K, K, Set_Of_Type> _t;
	};
}


void test_set()
{
	lh::set<int> s;
	int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	for (auto e : a)
	{
		s.insert(e);
	}

	for (auto e : s)
	{
		cout << e << " ";
	}
	cout << endl;

	//lh::set<int>::iterator it = s.begin();
	//while (it != s.end())
	//{

	//	cout << *it << " ";
	//	++it;
	//}
	//cout << endl;


	lh::set<int>::iterator it = s.end(); 
	while (it != s.begin())
	{
		--it;

		cout << *it << " ";
	}
	cout << endl;
}
